package com.lit.server;

import java.net.InetAddress;
import java.util.HashMap;
import java.util.Vector;

public class ConnectedUser 
{
	private String username;
	private Vector<InetAddress> LL = new Vector<InetAddress>(3);
	
	public ConnectedUser(String username, InetAddress ip)
	{
		if(!username.isEmpty() && username != null && ip != null)
		{
			this.username = username;
			this.LL.setElementAt(ip, 1);
		}
		else
			throw new NullPointerException ("Both arguments required. Cannot be empty or null");
	}

	public String getUsername() 
	{
		return username;
	}

	public InetAddress getPrev() 
	{
		return getArrayData(0);
	}
	
	public InetAddress getNext() 
	{
		return getArrayData(2);
	}
	
	public InetAddress getIP()
	{
		return getArrayData(1);
	}
	
	private InetAddress getArrayData(int index)
	{
		InetAddress returnval = null;

			if((returnval = LL.get(index)) == null)
				throw new NullPointerException ("Uninitialized. Must use SetPrev and setNext methods");
			
		return returnval;
		
	}

	public void setPrev(InetAddress in) 
	{
		if(in != null)
			LL.setElementAt(in, 0);
		else
			throw new NullPointerException ("No way Jose. No nulls allowed.");
	}
	
	public void setNext(InetAddress in) 
	{
		if(in != null)
		LL.setElementAt(in, 2);
		else
			throw new NullPointerException ("No way Jose. No nulls allowed.");
	}
	
	public void setDisconnected() 
	{
		LL.setElementAt(null, 2);
		LL.setElementAt(null, 0);
	}
	

}
